<template>
    <div>
        <div
        class="item"
        v-for="(item, index) of list"
        :key="index"
        @click="!item.children && handleBookClick(index)"
        >
            <div class="item-title border-bottom" >
                <span class="item-title-icon"></span>
                <span ref="title">{{item.title}}</span>
                <div
                class="item-price"
                >
                    <span class="before">￥</span>
                    <em class="price" ref="price">{{item.price}}</em>
                    <span class="after">起</span>
                </div>
            </div>
        <div
            v-if="item.children"
            class="item-children"
            >
                <detail-list
                :list="item.children">
                </detail-list>
            </div>
        </div>
        <fade-opacity>
            <common-book
            :price="price"
            :title="title"
            v-show="showBook"
            @close="handleCloseBook"
            ></common-book>
        </fade-opacity>
    </div>
</template>

<script>
import CommonBook from 'common/book/book'
import FadeOpacity from 'common/fade/fadeOpacity'
export default {
    name: 'DetailList',
    props: {
        list: Array
    },
    components: {
        CommonBook,
        FadeOpacity
    },
    data () {
        return {
            showBook: false,
            price: '',
            title: ''
        }
    },
    methods: {
        handleBookClick (index) {
            this.showBook = true
            this.title = this.$refs.title[index].innerText
            this.price = this.$refs.price[index].innerText
        },
        handleCloseBook () {
            this.showBook = false
        }
    }
}
</script>

<style lang="stylus" scoped>
    .item-title
        position relative
        line-height .8rem
        font-size .32rem
        padding .2rem
        .item-title-icon
            position relative
            left .06rem
            top .06rem
            display: inline-block
            width: .36rem
            height: .36rem
            background: url(//s.qunarzz.com/piao/image/touch/sight/detail.png) 0 -.45rem no-repeat
            margin-right: .1rem
            background-size: .4rem 3rem
        .item-price
            display none
            position absolute
            bottom 0
            right 0
            color #888
            font-size 0
            .before
                font-size .2rem
                color #ff8300
            .price
                color #ff8300
                font-size .46rem
                margin-left 0
            .after
                font-size .2rem
    .item-children
        padding 0 .12rem
        .item-title
            font-size .29rem
        .item-price
            display block
</style>
